package com.lvchen.ui.onefunction;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;

import com.lvchen.R;
import com.lvchen.common.MyApplication;
import com.lvchen.common.base.BaseFragment;
import com.lvchen.common.utils.UIHelper;
import com.lvchen.common.view.ContainsTwoItemGalleryView;
import com.lvchen.common.view.ViewAnimatorWordComponent;
import com.lvchen.datamodel.BannerModel;
import com.lvchen.datamodel.OneGalleryModel;
import com.lvchen.ui.onefunction.banner.BannerAdapter;
import com.makeramen.roundedimageview.RoundedImageView;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.siberiadante.titlelayoutlib.TitleBarLayout;
import com.wyt.searchbox.SearchFragment;
import com.wyt.searchbox.custom.IOnSearchClickListener;

import java.util.ArrayList;
import java.util.List;



/**
 * 功能一
 */
public class OneFragment extends BaseFragment {

    private TitleBarLayout tb_title;

    private ConvenientBanner cb_fo;
    private List<BannerModel> url=new ArrayList<BannerModel>();

    private RoundedImageView rv_fo,rv_fo2;

    private ViewAnimatorWordComponent vc_fo;
    private List<String> xiaoxi = new ArrayList<String>();

    private SearchFragment searchFragment;

    private ContainsTwoItemGalleryView cg_fo;
    private OneGalleryAdapter adapter;
    private OneGalleryModel info;
    private List<OneGalleryModel> list = new ArrayList<OneGalleryModel>();
    private List<OneGalleryModel> savelist = new ArrayList<OneGalleryModel>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        mContentView = inflater.inflate(R.layout.fragment_one, container, false);

        ensureUi();

        getData();

        return mContentView;
    }

    private void ensureUi() {

        tb_title = (TitleBarLayout) mContentView.findViewById(R.id.tb_title);
        tb_title.setIsHaveLine(false);
        tb_title.setLeftBackViewVisible(View.GONE);

        tb_title.setRightText("搜索");
        tb_title.setRightTextClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                searchFragment.show(getFragmentManager(),SearchFragment.TAG);
            }
        });
        //搜索相关
        searchFragment = SearchFragment.newInstance();
        searchFragment.setOnSearchClickListener(new IOnSearchClickListener() {
            @Override
            public void OnSearchClick(String keyword) {
                MyApplication.getInstance().showToast(keyword);
            }
        });

        cb_fo = (ConvenientBanner) mContentView.findViewById(R.id.cb_fo) ;


        rv_fo = (RoundedImageView) mContentView.findViewById(R.id.rv_fo);
        rv_fo2 = (RoundedImageView) mContentView.findViewById(R.id.rv_fo2);

        ImageLoader.getInstance().displayImage("http://osrchu6pc.bkt.clouddn.com/banne-0510-01.png",rv_fo);
        ImageLoader.getInstance().displayImage("http://imgshe.chnloan.com/O2O_1.png",rv_fo2);

        vc_fo = (ViewAnimatorWordComponent) mContentView.findViewById(R.id.vc_fo);

        cg_fo = (ContainsTwoItemGalleryView) mContentView.findViewById(R.id.cg_fo);
        adapter = new OneGalleryAdapter(mActivity, savelist);
        cg_fo.setAdapter(adapter);




    }


    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);

    }

    @Override
    protected View getContentView() {
        return mContentView;
    }

    private void getData() {

        url.clear();
        xiaoxi.clear();
        list.clear();
        savelist.clear();

        BannerModel info1=new BannerModel();
        info1.setTitle("标题");
        info1.setJumpurl("http://www.baidu.com");
        info1.setPhotourl("http://osrchu6pc.bkt.clouddn.com/banne-0510-01.png");
        url.add(info1);
        BannerModel info2=new BannerModel();
        info2.setTitle("标题");
        info2.setJumpurl("http://www.baidu.com");
        info2.setPhotourl("http://imgshe.chnloan.com/O2O_1.png");
        url.add(info2);

        cb_fo.setPages(new CBViewHolderCreator<BannerAdapter>() {
            @Override
            public BannerAdapter createHolder() {
                return new BannerAdapter();
            }
        }, url)
                //设置两个点图片作为翻页指示器，不设置则没有指示器，可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
                .setPageIndicator(new int[]{R.mipmap.img_bannerpoint_no, R.mipmap.img_bannerpoint_yes})
                //设置指示器的方向
                .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL);
//                        cb_fo.setManualPageable(false);//设置不能手动影响
        cb_fo.startTurning(4000);

        for (int i=0;i<10;i++){
            String msg="调尼玛！黄金比例最好喝";
            xiaoxi.add(msg);
        }
        vc_fo.setStrings(xiaoxi);

        //gallery
        for (int i = 0; i < 9; i = i + 2) {
            if (9 > 1) {
                info = new OneGalleryModel();
                if (9 % 2 == 0) {
                    info.setId(i+"");
                    info.setLogo("http://hidriends.oss-cn-hangzhou.aliyuncs.com/images/20180418/1524047868.jpg");
                    info.setNewlogo("http://hidriends.oss-cn-hangzhou.aliyuncs.com/images/20180418/1524047868.jpg");
                    info.setName("奶茶");
                    info.setIndustry_name("店铺");
                    info.setBrief("调尼玛");
                    info.setMin_amount("10000");
                    info.setMax_amount("10000");
                    info.setValuation("黄金比例最好喝");
                    info.setMin_invest("10000");
                    info.setFinance_amount("10000");
                    info.setRaise_amount("10000");
                    info.setPercent("10");
                    info.setPeriod_name("黄金比例最好喝");
                    info.setId2(i+"");
                    info.setLogo2("http://hidriends.oss-cn-hangzhou.aliyuncs.com/images/20180124/1516762988.jpg");
                    info.setNewlogo2("http://hidriends.oss-cn-hangzhou.aliyuncs.com/images/20180124/1516762988.jpg");
                    info.setName2("奶茶");
                    info.setIndustry_name2("店铺");
                    info.setBrief2("调尼玛");
                    info.setMin_amount2("10000");
                    info.setMax_amount2("10000");
                    info.setValuation2("黄金比例最好喝");
                    info.setMin_invest2("10000");
                    info.setFinance_amount2("10000");
                    info.setRaise_amount2("10000");
                    info.setPercent2("10");
                    info.setPeriod_name2("黄金比例最好喝");
                    list.add(info);
                } else {
                    if (i == 9 - 1) {
                        info.setId(i+"");
                        info.setLogo("http://hidriends.oss-cn-hangzhou.aliyuncs.com/images/20180418/1524047868.jpg");
                        info.setNewlogo("http://hidriends.oss-cn-hangzhou.aliyuncs.com/images/20180418/1524047868.jpg");
                        info.setName("奶茶");
                        info.setIndustry_name("店铺");
                        info.setBrief("调尼玛");
                        info.setMin_amount("10000");
                        info.setMax_amount("10000");
                        info.setValuation("黄金比例最好喝");
                        info.setMin_invest("10000");
                        info.setFinance_amount("10000");
                        info.setRaise_amount("10000");
                        info.setPercent("10");
                        info.setPeriod_name("黄金比例最好喝");
                        list.add(info);
                    } else {
                        info.setId(i+"");
                        info.setLogo("http://hidriends.oss-cn-hangzhou.aliyuncs.com/images/20180418/1524047868.jpg");
                        info.setNewlogo("http://hidriends.oss-cn-hangzhou.aliyuncs.com/images/20180418/1524047868.jpg");
                        info.setName("奶茶");
                        info.setIndustry_name("店铺");
                        info.setBrief("调尼玛");
                        info.setMin_amount("10000");
                        info.setMax_amount("10000");
                        info.setValuation("黄金比例最好喝");
                        info.setMin_invest("10000");
                        info.setFinance_amount("10000");
                        info.setRaise_amount("10000");
                        info.setPercent("10");
                        info.setPeriod_name("黄金比例最好喝");
                        info.setId2(i+"");
                        info.setLogo2("http://hidriends.oss-cn-hangzhou.aliyuncs.com/images/20180124/1516762988.jpg");
                        info.setNewlogo2("http://hidriends.oss-cn-hangzhou.aliyuncs.com/images/20180124/1516762988.jpg");
                        info.setName2("奶茶");
                        info.setIndustry_name2("店铺");
                        info.setBrief2("调尼玛");
                        info.setMin_amount2("10000");
                        info.setMax_amount2("10000");
                        info.setValuation2("黄金比例最好喝");
                        info.setMin_invest2("10000");
                        info.setFinance_amount2("10000");
                        info.setRaise_amount2("10000");
                        info.setPercent2("10");
                        info.setPeriod_name2("黄金比例最好喝");
                        list.add(info);
                    }
                }
            } else if (9 == 1) {
                info = new OneGalleryModel();
                info.setId(i+"");
                info.setLogo("http://hidriends.oss-cn-hangzhou.aliyuncs.com/images/20180418/1524047868.jpg");
                info.setNewlogo("http://hidriends.oss-cn-hangzhou.aliyuncs.com/images/20180418/1524047868.jpg");
                info.setName("奶茶");
                info.setIndustry_name("店铺");
                info.setBrief("调尼玛");
                info.setMin_amount("10000");
                info.setMax_amount("10000");
                info.setValuation("黄金比例最好喝");
                info.setMin_invest("10000");
                info.setFinance_amount("10000");
                info.setRaise_amount("10000");
                info.setPercent("10");
                info.setPeriod_name("黄金比例最好喝");
                list.add(info);
            }
        }
        //优秀项目
        savelist.addAll(list);
        adapter.change(savelist);


    }

    @Override
    public void onPause() {
        super.onPause();
        cb_fo.stopTurning();
    }

}